package com.mujin.keji.collectionsystem.module.outboundtask.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.BoundTaskDto;
import com.mujin.keji.collectionsystem.utils.NumberUtils;

import java.util.List;


/**
 * 拜访任务列表适配器
 *
 * @author weishixiong
 * @Time 2018-03-21
 */

public class AssimilatorListAdapter extends RecyclerView.Adapter<AssimilatorListAdapter.ViewHolder> {

    private Activity mContext;
    private List<BoundTaskDto> datas;
    private int status;//4  超时回收。5 状态改变回收 应该有状态

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public AssimilatorListAdapter(Activity context, List<BoundTaskDto> datas) {
        mContext = context;
        this.datas = datas;


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_assimilator, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(datas.get(position).getVisitName());
        holder.tvAccount.setText("最新欠款额：" + NumberUtils.twoDecimalPlaces(datas.get(position).getLatestDebtMoney()));
        holder.tvDays.setText("逾期：" + (datas.get(position).getOverdueDay() == null ? "" : datas.get(position).getOverdueDay()) + "天");
        holder.tvAdress.setText(datas.get(position).getVisitAddress());
        holder.tvIdentity.setText(datas.get(position).getVisitRelation());
        holder.tvAllocateTime.setText(datas.get(position).getAllotTime());
        if (position == 0) {
            holder.vLine.setVisibility(View.GONE);
            holder.rlBg.setBackgroundResource(R.drawable.shape_button_white_top);
        } else if (position == datas.size() - 1) {
            holder.rlBg.setBackgroundResource(R.drawable.shape_button_white_bottom);
            holder.vLine.setVisibility(View.VISIBLE);
        } else {
            holder.rlBg.setBackgroundResource(R.color.color_white);
            holder.vLine.setVisibility(View.VISIBLE);
        }
        holder.tvLastStatus.setText(datas.get(position).getLastStatusName());
        if(getStatus()==4){
            holder.llData.setVisibility(View.INVISIBLE);
        }
        else{
            holder.llData.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvName;
        private TextView tvAccount;
        private TextView tvDays;
        private TextView tvAdress;
        private TextView tvIdentity;
        private TextView tvAllocateTime;
        private TextView tvVisit;
        private View vLine;
        private View itemView;
        private RelativeLayout rlBg;
        private TextView tvLastStatus;
        private LinearLayout llData;
        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvAccount = (TextView) itemView.findViewById(R.id.tv_account);
            tvDays = (TextView) itemView.findViewById(R.id.tv_days);
            tvAdress = (TextView) itemView.findViewById(R.id.tv_adress);
            tvIdentity = (TextView) itemView.findViewById(R.id.tv_identity);
            tvAllocateTime = (TextView) itemView.findViewById(R.id.tv_allocate_time);
            tvVisit = (TextView) itemView.findViewById(R.id.tv_visit);
            vLine = (View) itemView.findViewById(R.id.v_line);
            rlBg = (RelativeLayout) itemView.findViewById(R.id.rl_bg);
            tvLastStatus = (TextView) itemView.findViewById(R.id.tv_last_status);
            llData = (LinearLayout) itemView.findViewById(R.id.ll_data);
        }

    }
}
